# Author 阳某
'''1.打开文件，得到文件句柄并赋值给一个变量
2.通过句柄对文件进行操作
3.关闭文件'''
'''# data = open("book",encoding = "utf-8").read()
# print(data)
f = open("book",'r',encoding = "utf-8")#文件句柄
data = f.read()#一遍就读完
#a == append  追加
# data2 = f.read()
# print(data)
# print('-----------data2------%s---'%data2)
print(data)'''
'''# f1 = open('book1','w',encoding='utf-8')
f1 = open('book1','a',encoding='utf-8')
f1.write("\n金瓶梅.....\n")#创建一个文件，覆盖’w'模式
f1.write('十宗罪////')
f1.close()'''

# f = open("book",'a+',encoding = "utf-8")#文件句柄   追加读


#f = open("book",'rb')#文件句柄   以二进制方式读该文件，网络传输只能用二进制
#f = open("book",'wb')#文件句柄   以二进制写文件


'''f = open("book",'r+',encoding = "utf-8")#文件句柄   读写
f = open("book",'r+',encoding = "utf-8")#文件句柄   读写
print(f.readline())
print(f.readline())
print(f.readline())
print(f.tell())
f.write("-----diao-----")#读和追加的方式
print(f.readline())'''

f = open("book1", 'w+', encoding ="utf-8")#文件句柄   写读,,没多大用处
f.write("-----diao-----1\n")
f.write("-----diao-----1\n")
f.write("-----diao-----1\n")
f.write("-----diao-----1\n")
print(f.tell())
f.seek(10)#回到第10个位置
print(f.tell())
print(f.readline())
f.write("should be at the begining of the second line")
f.close()

'''f1 = open("book1",'a',encoding = "utf-8")#文件句柄
f1.seek(10)
f1.truncate(20)#从第几个位置开始截断'''


'''print(f.tell())
#print(f.read(5))#5个字符
print(f.readline())
print(f.readline())
print(f.readline())
print(f.tell())
f.seek(0)
print(f.readline())

print(f.encoding)
# print(f.fileno)
print(f.name)
print (f.flush())#刷新缓存'''


'''# print(f.readlines())#列表
# print(f.readline())
# print(f.readline())
# print(f.readline())
# for i in range(5):
#     print(f.readline())
# for line in f.readlines():
#     print(line.strip())'''

'''count = 0
for line in f:
    if count == 6:
        print ('--------')
        count += 1
        continue
    print(line)#一行行读，进内存里，这个效率高
    count += 1
'''

'''只适合小文件
for index,line in enumerate(f.readlines()):
    if index ==6:
        print ('--------')
        continue
    print(line.strip())'''


